import axios from 'axios'

class FileTranFunction {
    static download(source_path) {
        console.log(source_path)
        return false;
    }

    static upload(target_path) {
        console.log(target_path)
        return false;
    }

    static uploadBlob4Package(blob, target_path, para, callbak) {
        let file = new File([blob], "package", {type: blob.type})
        let form = new FormData();
        form.append("file", file);
        form.append("type", blob.type);
        form.append("host", para.host);
        form.append("username", para.username);
        form.append("password", para.password);
        form.append("script_package_dir2rpm", para.script_package_dir2rpm);
        axios.post(target_path, form).then(function (response) {
            // console.log(response)
            callbak(response)
        }).catch(function (error) { // 请求失败处理
            console.log(error);
        });

    }

    static move_file2next_server4package(source_path, target_path) {
        fetch(source_path).then(function (response) {
            response.blob().then(function (blob) {
                FileTranFunction.uploadBlob4Package(blob, target_path)
            })
        })
    }


}

export default FileTranFunction;
